<template>
  <view>
    <view class="goods-list">
      <block v-for="(goods, i) in goodsList" :key="i">
        <my-goods :goods="goods"></my-goods>
      </block>
      <view class=""  v-if="flag">
        我是有底线的~~~~~
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        // 请求参数对象
        queryObj: {
          // 查询关键词
          query: '',
          // 商品分类Id
          cid: '',
          // 页码值
          pagenum: 1,
          // 每页显示多少条数据
          pagesize: 10
        },
        // 商品列表的数据
        goodsList: [],
        // 总数量，用来实现分页
        total: 10,
        flag:false

      };
    },
    onLoad(option) {
      console.log(option, 666);
      this.queryObj.cid = option.cat_id
      this.getGoodsList()
    },
    /* 实现上拉*/
    onReachBottom() {
      this.queryObj.pagenum += 1
      this.getGoodsList()
      console.log(1111);
    },
    onPullDownRefresh(){
      console.log(222);
      this.queryObj.pagenum =1
      this.goodsList= [],
      this.getGoodsList()
    },
    methods: {
      async getGoodsList() {
        if (this.goodsList.length >= this.total) {
          this.flag=true
          return 
        }
        // 发起请求
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/goods/search', this.queryObj)
        if (res.meta.status !== 200) return uni.$showMsg()
        // 为数据赋值
        this.goodsList = [...this.goodsList, ...res.message.goods]
        this.total = res.message.total
      }
    }
  }
</script>

<style lang="scss">

</style>
